﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using V = Science.Mathematics.VectorCalculus;

namespace VectorCalculus5Ed.Chapter8.Section1
{
    public class Example02
    {
        public Example02()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
        public void Compute()
        {
            V.Function.ToLastType<double[], double[]> ff
                = new V.Function.ToLastType<double[], double[]>(func);
            V.Surface s = new V.Surface(ff);
            s.Parameter1StartValue = 0.0;
            s.Parameter1EndValue = 2.0*Math.PI;
            s.Parameter2StartValue = 0.0;
            s.Parameter2EndValue = a;

            V.Function.ToLastType<double, double[]> gg
                = new V.Function.ToLastType<double, double[]>(gunc);
            V.Path p = new V.Path(gg);
            p.ParameterFrom = 0.0;
            p.ParameterTo = 2.0 * Math.PI;

            V.Function.ToLastType<double[], double> P
               = new V.Function.ToLastType<double[], double>(pf);

            V.Function.ToLastType<double[], double> Q
               = new V.Function.ToLastType<double[], double>(qf);

            V.GreenTheorem obj = new V.GreenTheorem(p, P, Q, s);
            obj.Compute();

            result += obj.LeftHandSideBestEstimation.ToString() + "\r\n";
            result += obj.RightHandSideBestEstimation.ToString() + "\r\n";
            result += obj.RightHandSideStandardDeviation.ToString() + "\r\n";
      
            result += (3.0/8.0*Math.PI*a*a).ToString() + "\r\n";
        }
        private double[] func(double[] u)
        {
            double[] x = new double[3];
            x[0] = u[1] * Math.Pow(Math.Cos(u[0]), 3.0);
            x[1] = u[1] * Math.Pow(Math.Sin(u[0]), 3.0);
            x[2] = 0.0;
            return x;
        }
        private double a = 2.0;
        private double[] gunc(double t)
        {
            double[] x = new double[3];
            x[0] = a*Math.Pow(Math.Cos(t),3.0);
            x[1] = a*Math.Pow(Math.Sin(t),3.0);
            x[2] = 0.0;
            return x;
        }

        private double pf(double[] x)
        {
            return -x[1]/2.0;
        }

        private double qf(double[] x)
        {
            return x[0]/2.0;
        }
    }
}
/*
4.71238898036606
4.71234556041428
0.000157450538742225
4.71238898038469
*/


